import os

from excel_operator.ExcelWriter import ExcelWriter
from excel_operator.ExcelReader import ExcelReader
import difflib

from log.Logger import Logger


class VideoCopier:
    def __init__(self):
        self.path_str = "E:/data/swimsuit&underwear"
        self.log = Logger("D:/logs/videa_join.log", level='debug')
        self.file_list = []

    def get_files_name(self):
        for root, dirs, files in os.walk(self.path_str, topdown=False):
            for file in files:
                location = file.find(".")
                file = file[:location]
                if file == 'swimsuit&underwear' or file.startswith("内衣泳装"):
                    continue
                if self.check_replica(file) is False:
                    self.file_list.append(file)
        return self.file_list

    def check_replica(self, file_name):
        reader = ExcelReader()
        name_list = reader.read_columns(0)
        for i in range(0,len(name_list)):
            # print(name_list[i])
            radio = difflib.SequenceMatcher(None, name_list[i], file_name).quick_ratio()
            # print(radio)
            if radio > 0.95:
                self.log.logger.info("The file name :'" + file_name + "' is similar to the "
                                     + str(i) + " row, similar radio:" + str(radio))
                print("The file name :" + file_name + "is similar to the " + str(i) + " row, similar radio:"
                      + str(radio))
                return True
        return False


if __name__ == '__main__':
    video_copier = VideoCopier()
    file_list = video_copier.get_files_name()
    excel_writer = ExcelWriter()
    excel_writer.write_excel_xls_append(file_list)
    # video_copier.check_replica("充满时尚的裁剪，亮色的色系更添一美感")
